/*
 *点击search组件  table组件的操作
 */

import { nextTick, ref } from "vue"
import pageTable from "@/components/page-table/page-table.vue"

type callbackFnType = (data?: any) => void

function usePageTable(queryCallback?: callbackFnType, resetCallback?: callbackFnType) {
  const tableRef = ref<InstanceType<typeof pageTable>>()
  function handleQueryClick(data: any) {
    if (queryCallback) queryCallback()
    tableRef.value?.fetchPageListData(data)
  }
  function handleResetClick() {
    if (resetCallback) resetCallback()
    nextTick(() => {
      tableRef.value?.refresh()
    })
  }

  function handleDeleteClick(item: any) {
    tableRef.value?.deletepageByIdAction({ zybh: item.zybh })
  }

  //点击羁室羁区下拉树 table的操作
  function handleSelectTreeClick(data: any) {
    tableRef.value?.fetchPageListData({ jsh: data.jsdm })
  }

  return {
    tableRef,
    handleQueryClick,
    handleResetClick,
    handleDeleteClick,
    handleSelectTreeClick,
  }
}

export default usePageTable
